/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, {Component} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Navigator,
  Image,
} from 'react-native';
import TabNavigator from 'react-native-tab-navigator';
import Popularpage from './Popularpage';
import AsyncStorage from '../AsyncStorage'
import MyPage from "./my/MyPage";
export default class HomePage extends Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedTab: "profile",
    }
  }

  render() {
    return (
      <View style={styles.container}>
        <TabNavigator>
          <TabNavigator.Item
            selected={this.state.selectedTab === 'profile'}
            title="Profile"
            selectedTitleStyle={{color: '#2197f3'}}
            renderIcon={() => <Image style={styles.image} source={require("../../res/images/ic_trending.png")}/>}
            renderSelectedIcon={() => <Image style={[styles.image, {tintColor: '#2197f3'}]}
                                             source={require("../../res/images/ic_trending.png")}/>}
            onPress={() => this.setState({selectedTab: 'profile'})}>
            <Popularpage/>
          </TabNavigator.Item>
          <TabNavigator.Item
            selected={this.state.selectedTab === 'home'}
            title="Home"
            selectedTitleStyle={{color: 'green'}}
            renderIcon={() => <Image style={styles.image} source={require("../../res/images/ic_polular.png")}/>}
            renderSelectedIcon={() => <Image style={[styles.image, {tintColor: "green"}]}
                                             source={require("../../res/images/ic_polular.png")}/>}
            badgeText="1"
            onPress={() => this.setState({selectedTab: 'home'})}>
            <AsyncStorage/>
          </TabNavigator.Item>
          <TabNavigator.Item
            selected={this.state.selectedTab === 'news'}
            title="news"
            selectedTitleStyle={{color: 'yellow'}}
            renderIcon={() => <Image style={styles.image} source={require("../../res/images/ic_favorite.png")}/>}
            renderSelectedIcon={() => <Image style={[styles.image, {tintColor: "yellow"}]}
                                             source={require("../../res/images/ic_favorite.png")}/>}
            badgeText="1"
            onPress={() => this.setState({selectedTab: 'news'})}>
            <View style={styles.page3}></View>
          </TabNavigator.Item>
          <TabNavigator.Item
            selected={this.state.selectedTab === 'treeding'}
            title="treeding"
            selectedTitleStyle={{color: 'yellow'}}
            renderIcon={() => <Image style={styles.image} source={require("../../res/images/ic_tiaozhuan_up.png")}/>}
            renderSelectedIcon={() => <Image style={[styles.image, {tintColor: "yellow"}]}
                                             source={require("../../res/images/ic_tiaozhuan_up.png")}/>}
            badgeText="1"
            onPress={() => this.setState({selectedTab: 'treeding'})}>
            <MyPage {...this.props}></MyPage>
          </TabNavigator.Item>
        </TabNavigator>


      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF',
  },
  image: {
    height: 22,
    width: 22
  },
  page1: {
    flex: 1,
    backgroundColor: 'blue'
  },
  page2: {
    flex: 1,
    backgroundColor: 'yellow'
  },
  page3: {
    flex: 1,
    backgroundColor: "red"
  },
  page4:{
    flex:1,
    backgroundColor:'green'
  }
});

